package demo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.Objects;
import java.util.PriorityQueue;

/**
 * @Desciption:
 * @Author: feixiang.li
 * @date: 2024-07-24 14:13
 **/
public class Test2 {

    @Data
    public static class Student implements Comparable<Student> {
        private String name;
        private int age;

        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }

        @Override
        public int compareTo(Student o) {
            return this.age - o.age;
        }
    }

    public static void main(String[] args) {
        PriorityQueue<Student> priorityQueue = new PriorityQueue<>();

        priorityQueue.offer(new Student("张三", 18));
        priorityQueue.offer(new Student("李四", 17));
        priorityQueue.offer(new Student("王五", 19));

        System.out.println(priorityQueue.poll()); // 运行结果：1
        System.out.println(priorityQueue.poll()); //          2
        System.out.println(priorityQueue.poll());
    }
}
